package com.icid.store.command
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.icid.store.business.delegate.PdfDelegate;
	import com.icid.store.event.GetPdfListEvent;
	import com.icid.store.model.PdfModelLocator;
	import com.icid.store.vo.PdfVO;
	
	import mx.rpc.IResponder;

	public class GetPdfListCommand extends CommandBase implements ICommand, IResponder
	{
		private var delegate:PdfDelegate;
		private var getPdfListEvent:GetPdfListEvent;
		private var pdfModel:PdfModelLocator = PdfModelLocator.getInstance();
		public function GetPdfListCommand()
		{
			super();
			delegate = new PdfDelegate(this);
		}
		
		override public function execute(event:CairngormEvent):void
		{
			getPdfListEvent = GetPdfListEvent(event);
			delegate.read(getPdfListEvent.pid);
		}
		
		override public function result(data:Object):void
		{
//			trace(data.result);
			pdfModel.pdfList.removeAll();
			for(var i:int=0;i<data.result.length;i++)
			{
				var pdfVO:PdfVO = new PdfVO();
				
				pdfVO.description = data.result[i].description;
				pdfVO.id = data.result[i].id;
				pdfVO.time = data.result[i].time;
				pdfVO.title = data.result[i].title;
				pdfVO.url = data.result[i].url;
				
				pdfModel.pdfList.addItem(pdfVO);
			}
			pdfModel.pdfList.refresh();
		}
	}
}